package com.qpf.mycms.api.pojo;

import com.qpf.mycms.api.enums.HttpStatusEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "响应返回数据对象")
public class ResponseResult<T>{
    @Schema(title = "响应码", example = "200")
    private Integer code;
    @Schema(title = "是否成功", example = "true")
    private Boolean success;
    @Schema(title = "返回信息")
    private String message;
    @Schema(title = "数据")
    private T data;

    private static <T> ResponseResult<T> response(Integer code, Boolean success, String message, T data){
        return new ResponseResult<T>(code, success, message, data);
    }
    public static <T> ResponseResult<T> success(Integer code, String message, T data){
        return response(code, true, message, data);
    }
    public static <T> ResponseResult<T> success(String message, T data){
        return success(HttpStatusEnum.SUCCESS.getValue(), message, data);
    }
    public static <T> ResponseResult<T> success(T data){
        return success(HttpStatusEnum.SUCCESS.getValue(), "返回成功", data);
    }
    public static <T> ResponseResult<T> success(String message){
        return success(message, null);
    }
    public static <T> ResponseResult<T> success(){
        return success("操作成功");
    }
    public static <T> ResponseResult<T> success(HttpStatusEnum httpStatusEnum){
        return success(httpStatusEnum.getValue(), httpStatusEnum.getDesc(), null);
    }
    public static <T> ResponseResult<T> fail(Integer code, String message){
        return response(code, false, message, null);
    }
    public static <T> ResponseResult<T> fail(){
        return fail(HttpStatusEnum.ERROR.getValue(), HttpStatusEnum.ERROR.getDesc());
    }
    public static <T> ResponseResult<T> fail(String message){
        return fail(HttpStatusEnum.ERROR.getValue(), message);
    }
    public static <T> ResponseResult<T> fail(HttpStatusEnum httpStatusEnum){
        return fail(httpStatusEnum.getValue(), httpStatusEnum.getDesc());
    }
}
